package cn.neusoft.mapper;

import cn.neusoft.pojo.Business;
import cn.neusoft.query.BaseQuery;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BusinessMapper extends BaseMapper<Business>{
	@Insert({"<script>",
			"insert into t_business(businessAccount, businessName, businessAddress, businessExplain, businessImg, startPrice, deliveryPrice, remarks)",
			"        values(#{businessAccount}," ,
			"               #{businessName}," ,
			"               #{businessAddress}," ,
			"               #{businessExplain}," ,
			"               #{businessImg}," ,
			"               #{startPrice}," ,
			"               #{deliveryPrice}," ,
			"               #{remarks})",
			"</script>"})
	int add(Business business);

	@Update({"<script>",
			"update t_business set" ,
			"businessAccount=#{businessAccount}," ,
			"businessName=#{businessName}," ,
			"businessAddress=#{businessAddress}," ,
			"businessExplain=#{businessExplain}," ,
			"businessImg=#{businessImg}," ,
			"startPrice=#{startPrice}," ,
			"deliveryPrice=#{deliveryPrice}," ,
			"remarks=#{remarks}" ,
			"where businessId=#{businessId}",
			"</script>"})
	int update(Business business);

	@Delete("delete from t_business where businessId=#{businessId}")
	int delete(Integer id);

	@Select("select businessId, businessAccount, businessName, businessAddress, businessExplain, businessImg, startPrice, deliveryPrice, remarks\n" +
			"from t_business where businessId=#{businessId}")
	Business getById(Integer id);

	@Select({"<script>",
			"select businessId, businessAccount, businessName, businessAddress, businessExplain, businessImg, startPrice, deliveryPrice, remarks",
			"from t_business" ,
			"<where>" ,
			"            <if test=\"businessName!=null and businessName!=''\">" ,
			"                and businessName like concat('%',#{businessName},'%')" ,
			"            </if>" ,
			"            <if test=\"businessAddress!=null and businessAddress!=''\">" ,
			"                and businessAddress like concat('%',#{businessAddress},'%')" ,
			"            </if>" ,
			"        </where>" ,
			" order by businessId desc",
			"</script>"})
	List<Business> getAll();


}
